<!--
 * @company : 版权所属 四川北星惯牌科技有限公司
 * @contact : 刘经理 19326416371
 -->
<template>
	<view>
		<view class="" ref="payview" id="target">支付</view>
		<view class="from-btn">
			<up-button text="立即支付" shape="circle" @click="submitLogin" loadingText="正在登录" :customStyle="{
				height:'88rpx',
				fontWeight: 'bold',
				fontSize: '34rpx',
				color: '#0A534F',
			}" color="linear-gradient( 270deg, #94DEAC 0%, #7CDEC7 47%, #79DED3 100%)"></up-button>
		</view>
		<button type='default' @click="onClick" fontColor="#ffffff">订 阅</button>
	</view>
</template>

<script setup>
	import {
		usePay
	} from '@/hooks/usePay.js';
	import {
		groupNotification
	} from '@/utils/groupNotification';
	import {
		userInfoStore
	} from '@/stores/user';
	const userStore = userInfoStore();
	const openId = ref(computed(() => userStore.openId))
	const payview = ref(null);
	const {
		appPay
	} = usePay();
	const submitLogin = async () => {
		const res = await $Api.order.submitOrder({
			type: 'wechat',
			method: 'miniapp',
			amount: 0.02,
			relationId: 1,
			relationType: 'Recharge'
		})
		if (res.code == 1) {
			const {
				data
			} = res
			appPay({
				provider: 'wxpay',
				timeStamp: data.pre_payment.timeStamp,
				nonceStr: data.pre_payment.nonceStr,
				package: data.pre_payment.package,
				signType: data.pre_payment.signType,
				paySign: data.pre_payment.paySign,
			}).then((res) => {
				console.log(res);
				uni.showToast({
					title: '支付成功'
				})
				setTimeout(() => {

				}, 600)
			}).catch((err) => {
				// console.log(err);
				uni.$u.toast(err)
			})
		} else {
			uni.$u.toast(res.msg);
		}
		if (openId.value) {

		} else {
			// userStore.getOpenId();
		}

	}
	const onClick = () => {
		groupNotification(() => {
			console.log('是的是的');
		})
	}
</script>

<style>

</style>